import qs from 'qs'
import axios from 'axios'
import Vue from 'Vue'
import { baseUrl } from '../../config/base'

//axios.defaults.withCredentials=true;
Vue.prototype.$http = axios

export default {
    state: {
        user: ''
    },
    getters: {
        user: function (state) {
          return state.user
        }
    },
    mutations: {
        getUser(state,data) {
            state.user = data
        }
    },
    actions: {
        loginUser(context,params) {
            return new Promise(function(resolve,reject){
              axios.post(baseUrl + '/user/loginUser', qs.stringify(params),{withCredentials : true,headers:{
                  'Content-Type':'application/x-www-form-urlencoded'
                }})
                .then(res=> {
                  console.log(res);
                  resolve(res.data)
                }).catch(err=> {
                console.log(err)
              })
          })
        }
    }
}
